package com.yjzx.util.racket.config;

import com.aliyun.openservices.ons.api.PropertyKeyConst;
import com.yjzx.util.common.util.ExceptionUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.Properties;

/**
 * @author yjzx
 * @date 2024/8/17
 * @description
 */
@Data
@Component
@AllArgsConstructor
@NoArgsConstructor
@ConfigurationProperties(prefix = "rocketmq")
public class RocketProperties {
    /**
     * 基本信息
     */
    private String accessKey;
    private String secretKey;
    private String onsAddr;
    private String sendMsgTimeoutMillis;

    private Map<String,ProductProperties> exchangeMap;
    @Data
    public static class ProductProperties {
        private String topic;
        private String tag;
        private String groupId;
    }
    public Properties getMqProperties() {
        Properties properties = new Properties();
        properties.setProperty(PropertyKeyConst.AccessKey, this.accessKey);
        properties.setProperty(PropertyKeyConst.SecretKey, this.secretKey);
        properties.setProperty(PropertyKeyConst.NAMESRV_ADDR, this.onsAddr);
        return properties;
    }

    public ProductProperties getProductProperties(String exchangeName) {
        if (exchangeMap.containsKey(exchangeName)) {
            return exchangeMap.get(exchangeName);
        }
        ExceptionUtil.throwException(RuntimeException.class,"exchangeName not found");
        return null;
    }

}
